<?php

namespace app\controller\user\controller;


use app\service\UserService;
use app\support\JwtHelper;
use app\support\ResponseHelper;
use DI\Attribute\Inject;
use Illuminate\Support\Arr;
use Shayvmo\WebmanAnnotations\Annotations\PostMapping;
use Shayvmo\WebmanAnnotations\Annotations\RestController;
use Webman\Http\Request;

#[RestController("/user/user")]
class UserController
{
    #[Inject]
    protected UserService $userService;
    #[PostMapping("/login")]
    public function login(Request $request)
    {
        $code = $request->input("code");
        $user = $this->userService->login($code);
        $token = JwtHelper::generateWx($user);

        return ResponseHelper::successJson(array("id" => $user->id, "openid" => $user->openid, "token" => Arr::get($token, 'access_token')));
    }
}